home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / GEDEV100.ZIP;1 / PASCAL.ZIP / PASCAL.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-10-12  |  1.7 KB  |  87 lines

  1. ;
  2. ; C <--> Pascal string conversion
  3. ;
  4. ; Written by Gerard J. van der Land
  5. ;
  6. ; Copyright (C) 1992 Gerard J. van der Land. All rights reserved.
  7. ;
  8. ; Last updates: 12-Oct-92
  9. ;
  10. ; Declaration:
  11. ;
  12. ; procedure c2p(dest : string ; src : pointer; max : byte); external;
  13. ; procedure p2c(dest : pointer; src : pointer; max : byte); external;
  14. ;
  15.  
  16. .MODEL TPASCAL
  17.  
  18. .CODE
  19.  
  20. public C2P
  21. public P2C
  22.  
  23. C2P proc near
  24.    push    bp
  25.    mov     bp, sp
  26.    mov     dx, ds
  27.    les     di, [bp+6]   ; ES:DI = src
  28.    xor     ax, ax
  29.    mov     cx, 0FFFFh
  30.    repnz   scasb
  31.    not     cx
  32.    dec     cx           ; CX = strlen(src)
  33.    mov     al, [bp+4]   ; AX = max (AH is still zero)
  34.    cmp     cx, ax
  35.    jb      c2p_copy
  36.    mov     cx, ax       ; if (CX >= max) CX = max
  37. c2p_copy:
  38.    lds    si, [bp+6]    ; DS:SI = src
  39.    les    di, [bp+10]   ; ES:DI = dest
  40.    mov    al, cl
  41.    stosb
  42.    shr    cx, 1
  43.    rep    movsw
  44.    adc    cx, cx
  45.    rep    movsb
  46.    mov    ds, dx
  47.    pop    bp
  48.    ret    10
  49. C2P endp
  50.  
  51. P2C proc near
  52.    push    bp
  53.    mov     bp, sp
  54.    push    ds
  55.    lds     si, [bp+6]   ; DS:SI = src
  56.    lodsb
  57.    xor     ch, ch
  58.    mov     cl, al       ; CX = Length(src)
  59.    mov     bh, ch
  60.    mov     bl, [bp+4]   ; BX = max
  61.    cmp     cx, bx
  62.    jb      p2c_copy
  63.    mov     cx, bx       ; if (CX >= max) CX = max
  64. p2c_copy:
  65.    mov     dx, cx
  66.    les     di, [bp+10]  ; ES:DI = dest
  67.    shr     cx, 1
  68.    rep     movsw
  69.    adc     cx, cx
  70.    rep     movsb
  71.  
  72.    mov     ax, cx
  73.    mov     cx, bx
  74.    sub     cx, dx
  75.    inc     cx
  76.    shr     cx, 1
  77.    rep     stosw        ; Fill unused bytes with NULs
  78.    adc     cx, cx
  79.    rep     stosb
  80.  
  81.    pop    ds
  82.    pop    bp
  83.    ret    10
  84. P2C endp
  85.  
  86. END
  87.